import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import "./assets/css/reset.css";
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
import "./assets/css/global.css"; // 公共样式库
import axios from "axios";

import MyPlugin from './assets/js/index';
Vue.use(MyPlugin);
/*axios.get('config.json').then(res=>{
  if(res.data.baseUrl){
    axios.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8;';
    axios.defaults.headers.get['Content-Type'] = 'application/json;charset=UTF-8;';
    axios.defaults.baseURL = res.data.baseUrl;
    axios.defaults.LinkURL = res.data.LinkUrl;
    Vue.prototype.config = res
    localStorage.setItem('baseJson',JSON.stringify(res.data))
    axios.interceptors.request.use(config => {
      // 在发送请求之前做些什么
      //判断是否存在token，如果存在将每个页面header都添加token
      if(localStorage.getItem("token")){
        config.headers.common['token']=localStorage.getItem("token")
      }
      return config;
    }, error => {
      // 对请求错误做些什么
      return Promise.reject(error);
    });
    router.beforeEach((to, from, next) => {
      if (to.meta.requireAuth) {
        // 判断该路由是否需要登录权限
        if (localStorage.getItem("token")) {
          // 通过vuex state获取当前的token是否存在
          next();
        } else {
          next({
            path: "/",
            query: { redirect: to.fullPath } // 将跳转的路由path作为参数，登录成功后跳转到该路由
          });
        }
      } else {
        next();
      }
    });
    Vue.prototype.$axios = axios;
    Vue.config.productionTip = false;

    Vue.use(ElementUI);
    new Vue({
      router,
      store,
      render: h => h(App)
    }).$mount("#app");
  }
})*/
import AxiosApi from "../src/request/axiosApi";
import axiosClass from "../src/request/axiosClass";
let axiosClassApi = new axiosClass()
axiosClassApi.readConfig('config.json').then((res)=>{
  //传入一个baseUrl
  AxiosApi.init(res.data.baseUrl,'yqUrl');
  AxiosApi.init(res.data.zfBaseUrl,'zgUrl');
  //将其加入到vue原型
  Vue.prototype.$AxiosApi = AxiosApi;
  Vue.use(ElementUI);
  new Vue({
    router,
    store,
    render: h => h(App)
  }).$mount("#app");
})


